#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 2035;
const int MOD = 998244353;

int n, m;
int a[N];
int head[N];
int ver[N << 1], Next[N << 1], tot;
void add(int u, int v) {
  ++tot;
  ver[tot] = v;
  Next[tot] = head[u];
  head[u] = tot;
}
int dfn[N], low[N], num;
int scc[N], cnt;
int st[N], top;
void tarjan(int u) {
  dfn[u] = low[u] = ++num;
  st[++top] = u;
  for (int i = head[u]; i; i = Next[i]) {
    int v = ver[i];
    if (!dfn[v]) {
      tarjan(v);
      low[u] = min(low[u], low[v]);
    } else if (!scc[v]) {
      low[u] = min(low[u], dfn[v]);
    }
  }
  if (dfn[u] == low[u]) {
    ++cnt;
    do {
      scc[st[top]] = cnt;
    } while (st[top--] != u);
  }
}
set<int> pre[N], nxt[N];
int ind[N];
ll dp[N][N], sum[N][N];
void toposort(int s, int t) {
  rep(i, 1, m) sum[s][i] = 1;
  queue<int> q;
  q.push(s);
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (int v : nxt[u]) {
      ind[v]--;
      if (!ind[v]) {
        rep(i, 1, m) {
          dp[v][i] = 1;
          for (int x : pre[v]) {
            dp[v][i] = (dp[v][i] * sum[x][i]) % MOD;
          }
        }
        rep(i, 1, m) sum[v][i] = (sum[v][i - 1] + dp[v][i]) % MOD;
        q.push(v);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) add(i, a[i]);
  rep(i, 1, n) if (!dfn[i]) tarjan(i);
  rep(u, 1, n) {
    for (int i = head[u]; i; i = Next[i]) {
      int v = ver[i];
      if (scc[u] != scc[v]) {
        pre[scc[v]].insert(scc[u]);
        nxt[scc[u]].insert(scc[v]);
      }
    }
  }
  int s = cnt + 1, t = cnt + 2;
  rep(i, 1, cnt) {
    if (pre[i].empty()) nxt[s].insert(i), pre[i].insert(s);
    if (nxt[i].empty()) nxt[i].insert(t), pre[t].insert(i);
  }
  rep(i, 1, t) ind[i] = pre[i].size();
  toposort(s, t);
  cout << dp[t][m];
  return 0;
}